package com.system.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.system.entity.FoodInfo;
import com.system.service.FoodServiceImpl;
import com.system.service.IFoodService;

public class ChangeFoodInfoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

    public ChangeFoodInfoServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html");
		request.setCharacterEncoding("utf-8");

		String oldID = request.getParameter("oldID");
		String foodNum = request.getParameter("id");
		String foodName = request.getParameter("name");
		String foodDate = request.getParameter("foodDate");
		String foodPest = request.getParameter("foodPest");
		String foodPestInfo = request.getParameter("foodPestInfo");
		String foodVeter = request.getParameter("foodVeter");
		String foodVeterInfo = request.getParameter("foodVeterInfo");
		String foodMetal = request.getParameter("foodMetal");
		String foodMetalInfo = request.getParameter("foodMetalInfo");
		String foodToxin = request.getParameter("foodToxin");
		String foodToxinInfo = request.getParameter("foodToxinInfo");
		String foodAddi = request.getParameter("foodAddi");
		String foodAddiInfo = request.getParameter("foodAddiInfo");
		String foodWrap = request.getParameter("foodWrap");
		String foodWrapInfo = request.getParameter("foodWrapInfo");

		IFoodService foodService = new FoodServiceImpl();
		FoodInfo foodInfo = new FoodInfo(foodNum, foodName, foodDate, foodPest, foodPestInfo, foodVeter, foodVeterInfo,
				foodMetal, foodMetalInfo, foodToxin, foodToxinInfo, foodAddi, foodAddiInfo, foodWrap, foodWrapInfo);
		PrintWriter out = response.getWriter();
		if (foodService.changeFoodInfo(foodInfo,oldID) == "1") {
			out.print("{\"code\":\"1\"}");
		} else {
			out.print("{\"code\":\"0\"}");
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
